package com.cqc.googleplay.view.part;

import java.text.Format;

import com.cqc.googleplay.R;
import com.cqc.googleplay.application.ImageLoaderOptions;
import com.cqc.googleplay.application.MyApplication;
import com.cqc.googleplay.bean.AppInfoBean;
import com.cqc.googleplay.http.NetUrl;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.content.Context;
import android.text.format.Formatter;
import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.TextView;

public class AppInfoPart {

	private Context context;
	private View part1View;
	private ImageView iv_part1;
	private TextView tv_name_part1;
	private RatingBar ratingBar;
	private TextView tv_download_number_part1;
	private TextView tv_version_part1;
	private TextView tv_date_part1;
	private TextView tv_size_part1;

	public AppInfoPart() {
		super();
		context = MyApplication.getContext();
	}

	public View getView() {
		part1View = View.inflate(context, R.layout.part1_app_info, null);
		findViews();
		return part1View;
	}

	private void findViews() {
		iv_part1 = (ImageView) part1View.findViewById(R.id.iv_part1);
		tv_name_part1 = (TextView) part1View.findViewById(R.id.tv_app_name_part1);
		ratingBar = (RatingBar) part1View.findViewById(R.id.ratingBar);
		tv_download_number_part1 = (TextView) part1View.findViewById(R.id.tv_download_number_part1);
		tv_version_part1 = (TextView) part1View.findViewById(R.id.tv_version_part1);
		tv_date_part1 = (TextView) part1View.findViewById(R.id.tv_date_part1);
		tv_size_part1 = (TextView) part1View.findViewById(R.id.tv_size_part1);
	}

	public void setData(AppInfoBean info) {
		ImageLoader.getInstance().displayImage(NetUrl.IMAGE_PREFIX + info.getIconUrl(), iv_part1, ImageLoaderOptions.options);
		tv_name_part1.setText(info.getName());
		ratingBar.setRating(info.getStars());
		tv_download_number_part1.setText("下载："+info.getDownloadNum());
		tv_version_part1.setText("版本："+info.getVersion());
		tv_date_part1.setText("日期："+info.getDate());
		tv_size_part1.setText("大小："+Formatter.formatFileSize(context, info.getSize()));

	}
}
